package com.qupai.controller.user;

import com.qupai.dto.PtShoppingCartDTO;
import com.qupai.dto.ShoppingCartDTO;
import com.qupai.entity.PtShoppingCart;
import com.qupai.entity.ShoppingCart;
import com.qupai.result.Result;
import com.qupai.service.PtShoppingCartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/ptShoppingCart")
@Slf4j
@RequiredArgsConstructor
@Tag(name = "普通-C端-购物车相关接口")
public class PtShoppingCartController {

    private final PtShoppingCartService ptShoppingCartService;
    
    @PostMapping("/add")
    @Operation(summary = "添加购物车")
    public Result<String> add(@RequestBody PtShoppingCartDTO ptShoppingCartDTO){
        log.info("添加购物车，商品信息为：{}",ptShoppingCartDTO);
        ptShoppingCartService.addShoppingCart(ptShoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查看购物车")
    public Result<List<PtShoppingCart>> list(){
        List<PtShoppingCart> list = ptShoppingCartService.showShoppingCart();
        return Result.success(list);
    }

    @DeleteMapping("/clean")
    @Operation(summary = "清空购物车")
    public Result<String> clean(){
        ptShoppingCartService.cleanShoppingCart();
        return Result.success();
    }

    @PostMapping("/sub")
    @Operation(summary = "删除购物车中一个奖品")
    public Result<String> sub(@RequestBody PtShoppingCartDTO shoppingCartDTO){
        ptShoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/del")
    @Operation(summary = "批量删除购物车中的奖品")
    public Result<String> del(@RequestParam List<Long> shoppingCartIds){
        log.info("批量删除奖品:{}",shoppingCartIds);
        ptShoppingCartService.deleteBatch(shoppingCartIds);
        return Result.success();
    }

}
